from __future__ import with_statement
import os
import sys
import warnings

reload(sys)
sys.setdefaultencoding('utf-8')

warnings.filterwarnings('ignore', '.*Unicode type received non-unicode bind param value.*',)

datadir = os.path.join(os.environ['HOME'], ".stocky")
if not os.path.isdir(datadir):
    os.makedirs(datadir)

## DEFAULTS ##
stocky_globals = dict (
    stocky_datadir = os.path.join(os.environ['HOME'], ".stocky"),
    stoploss = 10,
    debug = False # dev
    )

global_conf = "/etc/stocky/stocky.conf"

if os.path.exists(global_conf):
    try:
        execfile(global_conf, {}, stocky_globals)
    except:
        pass

local_conf = stocky_globals['stocky_datadir'] + "/stocky.conf"
if os.path.exists(local_conf):
    try:
        execfile(local_conf, {}, stocky_globals)
    except:
        pass

if stocky_globals['debug']:
    def debug(*args, **kw):
        print(args, kw)
else:
    def debug(*args, **kw): pass

__builtins__['stocky_globals'] = stocky_globals
__builtins__['debug'] = debug

